/// @tags: SegTreeDiv
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

namespace BlueQuantum {

int const N = 5e5 + 5;

struct E {
  int u, v, c;
} e[N];

struct Node {
  int x, c, d;
  Node() {}
  Node(int x, int c, int d) : x(x), c(c), d(d) {}
} p[N];

stack<Node> stk;

struct UnionFoundSet {
  int fa[N], dep[N];
  bool fw[N];

  inline bool check(int id) {
    int u = e[id].u, v = e[id].v, w = 0;
    while (fa[u] != u) w ^= fw[u], u = fa[u];
    while (fa[v] != v) w ^= fw[v], v = fa[v];
    return u != v || w;
  }

  inline void merge(int u, int v, int c) {
    int w = 1;
    while (fa[u] != u) w ^= fw[u], u = fa[u];
    while (fa[v] != v) w ^= fw[v], v = fa[v];
    if (u != v) {
      if (dep[u] > dep[v]) swap(u, v);
      fa[u] = v, fw[u] = w;
      dep[v] += (dep[u] == dep[v]);
      stk.push(Node(u, c, dep[u] == dep[v]));
    }
  }
} ufs[55];

int n, m, k, q;
vector<int> eve[N];
vector<int>::iterator ind[N];
vector<E> vec[N << 2];

void modify(int x, int l, int r, int L, int R, E const &v) {
  if (L <= l && r <= R) return vec[x].push_back(v);
  int mid = (l + r) >> 1;
  if (L <= mid) modify(x << 1, l, mid, L, R, v);
  if (mid < R) modify(x << 1 | 1, mid + 1, r, L, R, v);
}

void solve(int x, int l, int r) {
  int siz = stk.size();
  for (vector<E>::iterator i = vec[x].begin(); i != vec[x].end(); ++i) {
    ufs[i->c].merge(i->u, i->v, i->c);
  }
  if (l == r) {
    int id = p[l].x;
    ++ind[id], ufs[p[l].c].check(id) ? (puts("YES"), e[id].c = p[l].c) : (puts("NO"));
    modify(1, 1, q, l + 1, (*ind[id]) - 1, e[id]);
  } else {
    int mid = (l + r) >> 1;
    solve(x << 1, l, mid), solve(x << 1 | 1, mid + 1, r);
  }
  while (int(stk.size()) > siz) {
    int u = stk.top().x, c = stk.top().c;
    ufs[c].dep[ufs[c].fa[u]] -= stk.top().d;
    ufs[c].fa[u] = u, ufs[c].fw[u] = 0;
    stk.pop();
  }
}

inline int main() {
  cin >> n >> m >> k >> q;
  for (int i = 1; i <= m; ++i) cin >> e[i].u >> e[i].v;
  for (int i = 0; i <= k; ++i)
    for (int j = 1; j <= n; ++j) ufs[i].fa[j] = j;
  for (int i = 1; i <= q; ++i) cin >> p[i].x >> p[i].c, eve[p[i].x].push_back(i);
  for (int i = 1; i <= m; ++i) eve[i].push_back(q + 1), ind[i] = eve[i].begin();
  solve(1, 1, q);
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("CF576E Painting Edges.in", "r", stdin);
  freopen("CF576E Painting Edges.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
